package com.yami.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yami.shop.bean.dto.UltraGroupAutoRenewDTO;
import com.yami.shop.bean.model.MeltCloudUltraGroupCost;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.dao.MeltCloudUltraGroupCostMapper;
import com.yami.shop.service.MeltCloudUltraGroupCostService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
@Slf4j
@AllArgsConstructor
public class MeltCloudUltraGroupCostServiceImpl extends ServiceImpl<MeltCloudUltraGroupCostMapper, MeltCloudUltraGroupCost> implements MeltCloudUltraGroupCostService {
    
    private final MeltCloudUltraGroupCostMapper ultraGroupCostMapper;
   
    @Override
    public IPage<MeltCloudUltraGroupCost> page(PageParam<MeltCloudUltraGroupCost> pageParam, MeltCloudUltraGroupCost cost) {
        LambdaQueryWrapper<MeltCloudUltraGroupCost> lambdaQuery = Wrappers.lambdaQuery(MeltCloudUltraGroupCost.class);
        if (Objects.nonNull(cost.getMonths())) {
            lambdaQuery.eq(MeltCloudUltraGroupCost::getMonths, cost.getMonths());
        }
        if (Objects.nonNull(cost.getIsRenew())) {
            lambdaQuery.eq(MeltCloudUltraGroupCost::getIsRenew, cost.getIsRenew());
        }
        if (Objects.nonNull(cost.getIsHide())) {
            lambdaQuery.eq(MeltCloudUltraGroupCost::getIsHide, cost.getIsHide());
        }
        lambdaQuery.eq(MeltCloudUltraGroupCost::getIsDel, 0);
        lambdaQuery.orderByAsc(MeltCloudUltraGroupCost::getMonths).orderByAsc(MeltCloudUltraGroupCost::getEnergyValue);
        IPage<MeltCloudUltraGroupCost> page = this.page(pageParam, lambdaQuery);
        return page;
    }

    
    @Override
    public List<UltraGroupAutoRenewDTO> getAutoRenewUltraGroup() {
        List<UltraGroupAutoRenewDTO> list = ultraGroupCostMapper.getAutoRenewUltraGroup();
        return list;
    }

    
}
